package view.table.circle;

import java.util.ArrayList;
import java.util.List;

import model.Circle;
import view.table.CellValueChangeEvent;
import view.table.ExtendedAbstractTableModel;

public class CircleTableModel extends ExtendedAbstractTableModel {

	private static final long serialVersionUID = -491471296248705862L;
	private List<Circle> circles;

	public CircleTableModel(List<Circle> circles) {
		super();
		this.circles = circles;
		
	}

	@Override
	public int getRowCount() {
		return circles.size();
	}

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public String getColumnName(int col) {
		switch (col) {
		case 0:
			return "x";
		case 1:
			return "y";
		case 2:
			return "r";
		default:
			return "undefined";
		}
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Circle circle = circles.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return circle.getX();
		case 1:
			return circle.getY();
		case 2:
			return circle.getR();
		default:
			return "undefined";
		}
	}

	@Override
	public Class<?> getColumnClass(int c) {
		return Integer.class;
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		return true;

	}

	@Override
	public void setValueAt(Object value, int row, int col) {
		Circle circle = circles.get(row);
		fireChange(new CellValueChangeEvent(circle, value, col));
	}

	public void addCircle(Circle c){
		circles.add(c);
	}
	
	public void removeCircle(Circle c){
		circles.remove(c);
	}

	public void setCircles(ArrayList<Circle> circles) {
		this.circles = circles;
	}
	
}
